#!/usr/bin/python
# -*- coding: utf-8 -*-
'''
Created on 2011-6-15

@author: drowning
'''
from jiaju.model import Page


def get_page_info(page, pagesize):
    pageCount = Page.count()
    pageInfo = []
    if pageCount > 0 :
        pageInfo = Page.query(limit="%s, %s" % ((page-1) * pagesize, pagesize))
    return pageCount , pageInfo;


def get_page_one(id):
    if id:
        return Page.load(id=id);
    else:
        raise 'id is null'


def merge_page_info(page_info):
    page = Page()
    if page_info.get("delete") and page_info.get("id"):
        page.id = page_info.get("id")
        page.delete();
    elif page_info.get("edit") and page_info.get("id"):
        page.name = page_info.get("page_name")
        page.id = page_info.get("id")
        page.persist()
    elif page_info.get("page_name"):
        page.name = page_info.get("page_name")
        page.persist()
    else:
        print "nothing"
